package com.aegis.common.web.xss;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.SpringHandlerInstantiator;

/**
 * @Author wuweixin
 * 
 * @Version 1.0
 * @Descritube
 */
@Configuration
public class JacksonConfig {

    @Autowired
    private ApplicationContext applicationContext;

    /**
     * 注册这个bean，让jackson知道从spring容器中取自定义的JSON序列化反序列化解析器
     * 如果没注册这个bean，jackson就能获取到自定义的JSON解析器，应是yaml内配置了类似spring: jackson:的内容
     * @return
     */
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization() {
        return builder -> builder.handlerInstantiator(
                new SpringHandlerInstantiator(applicationContext.getAutowireCapableBeanFactory())
        );
    }

}
